﻿#include "../../libcat/include/cat-module.hpp"
#include "mode2_keyboard.hpp"

const char* get_name() {
	return u8"键盘模式";
}

const char* get_default_config_name() {
	return u8"data\\keyboard\\键盘模式示例.json";
}

void* Init(cat_data_t* settings) {

	keyboard::GetInstance()->Init(settings->json);

	return settings;
}

void* Release() {

	keyboard::GetInstance()->Release();
	
	return NULL;
};

void* Run(void* _window) {

	cat_window* cwindow = (cat_window*)_window;

	keyboard::GetInstance()->Draw(cwindow);

	return _window;
};


void* OnKeyPress(const cat_key_event* event, bool key_up) {

	keyboard::GetInstance()->OnKeyPress(event->native_vkey, key_up);
	return NULL;
};

void* Update(cat_data_t* settings) {

	keyboard::GetInstance()->Update(settings->json);

	return settings;
}

/*声明一个模块*/
CAT_DECLARE_MODULE()
bool cat_module_load() {
	cat_source_info keyboard{};
	keyboard.id = 2;
	keyboard.type = CAT_SOURCE_TYPE_MODE;
	keyboard.Init = Init;
	keyboard.Release = Release;
	keyboard.Run = Run;
	keyboard.OnKeyPress = OnKeyPress;
	keyboard.get_name = get_name;
	keyboard.get_default_config_name = get_default_config_name;
	keyboard.Update = Update;

	cat_register_source(&keyboard);
	return true;
}